package com.qingcheng.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.qingcheng.pojo.seckill.SeckillGoods;
import com.qingcheng.service.seckill.SeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.List;

@Service
public class SeckillGoodsServiceImpl implements SeckillGoodsService {
    @Autowired
    private RedisTemplate redisTemplate;

    /**
     * 获取指定时间的商品列表
     * @param time 开始时间字符串
     * @return
     */
    @Override
    public List<SeckillGoods> searchList(String time) {
        List list = redisTemplate.boundHashOps("SeckillGoods_" + time).values();
        return list;
    }

    /**
     * 根据id查询商品详情
     * @param time 开始时间
     * @param id 商品id
     * @return
     */
    @Override
    public SeckillGoods one(String time, Long id) {
        return (SeckillGoods)redisTemplate.boundHashOps("SeckillGoods_" + time).get(id);
    }
}
